<?php

/*
 * File  : kategori.php
 * Table : kategoris
 */
//session_start();
//cek session

if (!$_SESSION["USRID"] AND !$_SESSION["USRPASS"]) {
    header("location: ../index.php");
    exit();
}
//end
?>
<?php

$aksi = "cms/app/m_kategoris/aksi_kategori.php";
switch ($_GET["opr"]) {

// tampil kategori
    default:
        echo "<h2>Kategori Berita</h2>";
        echo " <input type='button' value='Tambah Kategori' onclick=\"window.location.href='?module=kategori&opr=tambah';\">";
        echo "  <table>";
        echo "   <tr><th>No</th><th>Nama Kategori</th><th>Aksi</th></tr>";
        $tampil = mysql_query("SELECT kategori_id, kategori_nama FROM kategoris ORDER BY kategori_id ASC");
        $no = 1;
        while ($row = mysql_fetch_array($tampil)) {
            echo "<tr><td>" . $row["kategori_id"] . "</td>";
            echo " <td>" . $row["kategori_nama"] . "</td>";
            echo " <td><a href='?module=kategori&opr=edit&id=" . $row["kategori_id"] . "'>Edit</a> | 
	               <a href='" . URLHOST . "$aksi?module=kategori&opr=hapus&id=" . $row["kategori_id"] . "' onClick=\"return confirm('Hapus Kategori " . $row["kategori_nama"] . "?')\" >Hapus</a>";
            echo " </td></tr>";
            $no++;
        }
        echo " </table>";
        break;

// tambah kategori
    case "tambah":
        echo "<h2>Tambah Kategori Berita</h2>";
        echo "<form method='POST' action='" . URLHOST . "$aksi?module=kategori&opr=input'>";
        echo "  <table>";
        echo "   <tr><td>Nama Kategori</td><td> : <input type='text' name='in_kategori_nama'></td></tr>";
        echo "   <tr><td colspan=2><input type='submit' name='submit' value='Simpan'> <input type=button value=Batal onclick=self.history.back()></td></tr>";
        echo "  </table>";
        echo "</form>";
        break;

// edit kategori  
    case "edit":
        $edit = mysql_query("SELECT * FROM kategoris WHERE kategori_id='" . $_GET["id"] . "'");
        $row = mysql_fetch_array($edit);

        echo "<h2>Edit Kategori Berita</h2>";
        echo " <form method='POST' action='" . URLHOST . "$aksi?module=kategori&opr=update'>";
        echo "  <input type='hidden' name='id' value='" . $row["kategori_id"] . "'>";
        echo "  <table>";
        echo "   <tr><td>Nama Kategori</td><td> : <input type ='text' name = 'in_kategori_nama' value ='" . $row["kategori_nama"] . "'></td></tr>";
        echo "   <tr><td colspan = 2><input type = submit value = Update><input type = button value = Batal onclick = self.history.back()></td></tr>";
        echo "  </table>";
        echo " </form>";
        break;
}
?>
